package com.tony.concurrentHashMap;

import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * HashMap在并发执行put操作时会引起死循环，是因为多线程会导致HashMap的Entry链表
 形成环形数据结构，一旦形成环形数据结构，Entry的next节点永远不为空，就会产生死循环获
 取Entry
 * @author tonywang
 * @date 8/9/2018
 */

public class HashMapDeadLoop {

    public static void main(String[] args) throws InterruptedException {
        final HashMap<String, String> map = new HashMap<String, String>(2);
        Thread t = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                new Thread(()->{
                    map.put(UUID.randomUUID().toString(),"");
                },"ftf" + i).start();
            }
        }, "ftf");
        t.start();
        t.join();
    }
}
